<template>
  <div id="app">
    <!-- <img alt="Vue logo" src="./assets/logo.png"> -->
    <HelloWorld msg="Welcome to Your Vue.js App"/>
    <button @click="generate_template">生成模板</button>

    <!-- <div v-if="this.showTemplate">
          <div :is="aaa">
            nihaowa
          </div>
      </div> -->
    <div id="box"></div>
  </div>
</template>

<script>
import HelloWorld from './components/HelloWorld.vue'
import Vue from 'vue'

export default {
  name: 'App',
  components: {
    HelloWorld
  },
  data(){
    return {
      showTemplate: false
    }
  },
  methods:{
    generate_template(){
      var fun1 = function show_something(){
        alert('show something');
      }
      var func_map = {show_something: fun1}
      var Aaa=Vue.extend({
        template:`<div><h3>我是标题3</h3><br><button @click="show_something">点击我</button></div>`,
        methods:{
          ...func_map
        }
      });
      Vue.component('aaa',Aaa);
      // // set 的用法https://www.jianshu.com/p/6f28f5abee08
      // // 将 aaa set为Aaa,立即更新视图
      // this.$set(this,'aaa', Aaa);

      this.showTemplate=true;
      new Vue({
        render: h => h(Aaa)
      }).$mount("#box")
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
